import GameObject, Animation, Character
from GameObject import *
from Character import *

class Enemy(Character):

    TARGET_REACHED_X_RANGE = 5
    TARGET_REACHED_Y_RANGE = 4

    AUTO_Y_ADJUST = 2

    def __init__(self):
        Character.__init__(self)


    #Name: moveTowardTarget
    #Description: Directs an Enemy toward the closest side of the targetRect and the bottom
    def moveTowardTarget(self, targetRect):
        inXRange = False
        inYRange = False
        if self.rect.right < targetRect.centerx - Enemy.TARGET_REACHED_X_RANGE:
            self.currentAnimation = self.RUN_SIDE
            self.facing = self.RIGHT
        elif self.rect.left > targetRect.centerx + Enemy.TARGET_REACHED_X_RANGE:
            self.currentAnimation = self.RUN_SIDE + self.LEFT
            self.facing = self.LEFT
        else:
            inXRange = True


        if self.rect.bottom < targetRect.bottom - Enemy.TARGET_REACHED_Y_RANGE:
            self.rect.top += Enemy.AUTO_Y_ADJUST
        elif self.rect.bottom > targetRect.bottom + Enemy.TARGET_REACHED_Y_RANGE:
            self.rect.top -= Enemy.AUTO_Y_ADJUST
        else: inYRange = True

        return inXRange and inYRange
            
